#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.web.helper;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by well on 16/7/15.
 */
public class DefaultExceptionResolver extends SimpleMappingExceptionResolver {

    private final static Logger log = LoggerFactory.getLogger(DefaultExceptionResolver.class);

    @Override
    protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response,
                                              Object handler, Exception ex) {
        Map<String, Exception> model = new HashMap<String, Exception>();
        model.put("ex", ex);

        String requestURI = request.getRequestURI();
        String errorVM = "500.vm";
        if (requestURI.startsWith("/admin")) {
            errorVM = "admin/500.vm";
        } else if (requestURI.startsWith("/wap")) {
            errorVM = "wap/500.vm";
        } else if (requestURI.startsWith("/webview")) {
            errorVM = "webview/500.vm";
        }
        log.error("", ex);
        return new ModelAndView(errorVM, model);

    }
}
